<?php
if(!defined('IN_ORA')) {
	exit('Access Denied');
}
class tag extends mod{
	function __construct(){
		parent::__construct();
	}
	/*** Tag ***/
	function v(){
		$key  = $GLOBALS['_param']['key'];
		if(!preg_match('/.*?Apache.*?/i',$_SERVER['SERVER_SOFTWARE'])){
			$key = iconv("gb2312",C("charset"),$key);
		}
		$key = clear_html($key);
		$key = preg_replace('/\'|\"|\=|update|select|delete|truncate|insert|drop|exec|eval|\$|\{|\}|\(|\)/i','',$key);
		if($key==""){
			redirect("index-index");
		}
		if(!$this->isCached("tag-v-key-$key")){
			/** 站点信息 **/
			$this->assign('sinfo',$this->db->getOne('select * from '.tn('info').' order by Id asc limit 1'));

			/** 导航信息 **/
			$this->assign('navs',$this->db->getAll('select * from '.tn('nav').' order by nav_sort desc'));

			/** 产品信息 **/
			import("lib.cat");
			$cates = cat_lib::getSubChild(0,2,' and cat_type=1');
			$this->assign('cates',$cates);
			/** 当前位置 **/
			$local = array();
			$local[] = array('url'=>get_url(true),'text'=>'产品标签_'.$key);
			$this->assign('local',$local);
			/** 专题标签 **/
			$this->assign('tags',$this->db->getAll('select * from '.tn('tags').' where tag_type=1 group by tag_name order by Id desc'));

			/******** Search ********/
			$this->assign('keywords',$key);
			$sql = "select * from ".tn('tags')." where tag_name = '$key'";
			$tag = array();
			$q = $this->db->query($sql);
			while ($row = $this->db->fetch_array($q)) {
				if(intval($row['tag_type']) === 1){//产品
					$sql  = "select op.*,oc.cat_name,oc.path,ocnt.content,opa.attr from ".tn('product')." op left join ".tn('cat')." oc ";
					$sql .=" on oc.Id = op.cat_id left join ".tn('content')." ocnt on ocnt.fk_id = op.Id ";
					$sql .=" left join ".tn('pattr')." opa on opa.p_id = op.Id where ocnt.ctype = 1 and op.Id = ".$row['fk_id'];
					$pro = $this->db->getOne($sql);
					if($pro){
						$tag['pros'][] = $pro;
					}
				}else{
					$sql = "select oa.*,oc.cat_name,oc.path,octont.content from ".tn('article')." oa ";
					$sql.= "left join ".tn('cat')." oc on oa.cat_id = oc.Id ";
					$sql.= "left join ".tn('content')." octont on octont.fk_id = oa.Id ";
					$sql.= " where octont.ctype = 0 and oa.id= ".$row['fk_id'];
					$art = $this->db->getOne($sql);
					if($art){
						$tag['arts'][] = $art;
					}
				}
			}
			$this->assign('tag',$tag);
			$this->assign('title',array_reverse($local));
		}
		$this->display("tag.html");
	}
}

?>